/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = test_ora.c                                        */
/*  NOTE      =                                                    */
/*  DATE      = 2016/03/10 by songbb                               */
/*******************************************************************/

#include <stdio.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "apmtest_cunit.h"
#include "frcomm.h"
#include "frmem.h"
#include "../../src/module/ldap/config.h"
#include "../../src/module/ldap/ldap_comm.h"
#include "../../src/module/ldap/ldap_core.h"
#include "t_ldap_comm/t_ldap_comm.h"


#include <frservice_mng.h>

static Frmemstat_mng g_st_memstat_mng={0,FR_MEMSTAT_COUNT_MAX};
static pthread_rwlock_t  g_memstat_rwlock = PTHREAD_RWLOCK_INITIALIZER;
static Frmem_env g_st_mem_env = {&g_st_memstat_mng, &g_memstat_rwlock};

FR_STATIC Frexp_ref g_st_expRef={NULL, NULL};
FR_STATIC Frexp_ref g_st_exp2Ref={NULL, NULL};
FR_STATIC Frservice_ref g_st_serviceRef={NULL, NULL};
FR_STATIC Frreport_session_ref g_st_report_session_Ref={NULL, NULL, NULL};
FR_STATIC Report_module g_st_report_moduleRef = {NULL, NULL, NULL, NULL, NULL};

ApmContext g_st_apm_context = {&g_st_expRef, &g_st_exp2Ref, &g_st_serviceRef, &g_st_report_session_Ref, &g_st_report_moduleRef, &g_st_mem_env};
void *g_p_apm_context = NULL;

void add_suites(FunType *p_func, int i_suites_len, FunType fp)
{
    int i_loop = 0;
    for (;i_loop < i_suites_len; i_loop++)
    {
        if (p_func[i_loop] == NULL)
        {
            p_func[i_loop] = fp;
            break;
        }
    }
}

int main(int argc, char **argv)
{
    if (fr_slab_init(&g_st_mem_env, MODULE_NAME) == NULL)
        return FR_FAIL;

    apmtest_cunit_registry();

    FunType fun_suites[1024];
    memset(fun_suites, 0x00, sizeof(fun_suites));
    int i_suites_len = sizeof(fun_suites) / sizeof(FunType);
    int i_loop = 0;

    //t_ldap_comm
    add_suites(fun_suites, i_suites_len, add_suite_ldap_get_attibutes);
    add_suites(fun_suites, i_suites_len, add_suite_ldap_get_attibutes1);
    add_suites(fun_suites, i_suites_len, add_suite_ldap_get_boolean);
    add_suites(fun_suites, i_suites_len, add_suite_ldap_get_derefAliases);
    add_suites(fun_suites, i_suites_len, add_suite_ldap_get_filter);
    add_suites(fun_suites, i_suites_len, add_suite_ldap_get_lenth);
    add_suites(fun_suites, i_suites_len, add_suite_ldap_get_message_id);
    add_suites(fun_suites, i_suites_len, add_suite_ldap_get_mod_operation);
    add_suites(fun_suites, i_suites_len, add_suite_ldap_get_protocol);
    add_suites(fun_suites, i_suites_len, add_suite_ldap_get_resp_info);
    add_suites(fun_suites, i_suites_len, add_suite_ldap_get_resultCode);
    add_suites(fun_suites, i_suites_len, add_suite_ldap_get_scope);
    add_suites(fun_suites, i_suites_len, add_suite_ldap_get_string);
    add_suites(fun_suites, i_suites_len, add_suite_ldap_get_string1);

    for (;i_loop < i_suites_len; i_loop++)
    {
        if (fun_suites[i_loop] != NULL && fun_suites[i_loop]() != 0)
        {
            CU_cleanup_registry();
            return CU_get_error();
        }
    }

    apmtest_cunit_unregistry();
    fr_slab_destroy();

    return 0;
}
